<template>
	<view class="container">
		<!-- #ifdef MP-TOUTIAO -->
		<view class="ad-container">
			<ad unit-id="ugu98j67oys4yymzql" type="feed"></ad>
		</view>
		<!-- #endif -->
		
		<view class="history-list">
			<view v-if="history.length === 0" class="empty-tip">
				<text>暂无历史记录</text>
			</view>
			<view v-else v-for="(item, index) in history" :key="index" class="history-item">
				<view class="number-info">
					<view class="numbers-container">
						<text class="number" v-for="(num, numIndex) in item.numbers" :key="numIndex">
							{{num}}{{numIndex < item.numbers.length - 1 ? ', ' : ''}}
						</text>
					</view>
					<text class="time">{{item.timestamp}}</text>
				</view>
			</view>
		</view>
		
		<button class="clear-btn" @click="clearHistory">清空历史</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				history: []
			}
		},
		onShow() {
			// 每次页面显示时重新加载历史记录
			this.loadHistory()
		},
		methods: {
			loadHistory() {
				const history = uni.getStorageSync('numberHistory') || []
				this.history = history
			},
			clearHistory() {
				uni.showModal({
					title: '提示',
					content: '确定要清空所有历史记录吗？',
					success: (res) => {
						if (res.confirm) {
							this.history = []
							uni.setStorageSync('numberHistory', [])
							// 通知首页更新历史记录
							const pages = getCurrentPages()
							const prevPage = pages[pages.length - 2]
							if (prevPage) {
								prevPage.$vm.history = []
							}
						}
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		padding: 20rpx;
		background-color: #f8f8f8;
		min-height: 100vh;
		box-sizing: border-box;
	}
	
	.ad-container {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #fff;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}
	
	.history-list {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-bottom: 40rpx;
	}
	
	.empty-tip {
		text-align: center;
		padding: 40rpx;
		color: #999;
	}
	
	.history-item {
		padding: 20rpx;
		border-bottom: 1px solid #eee;
	}
	
	.history-item:last-child {
		border-bottom: none;
	}
	
	.number-info {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}
	
	.numbers-container {
		width: 100%;
		word-break: break-all;
		line-height: 1.5;
	}
	
	.number {
		font-size: 32rpx;
		color: #333;
		font-weight: bold;
		display: inline;
	}
	
	.time {
		font-size: 24rpx;
		color: #999;
	}
	
	.clear-btn {
		width: 90%;
		height: 90rpx;
		line-height: 90rpx;
		background-color: #ff3b30;
		color: #fff;
		border-radius: 45rpx;
		margin: 0 auto;
		font-size: 32rpx;
		border: none;
		padding: 0;
		outline: none;
		border-width: 0;
		-webkit-appearance: none;
		box-shadow: none;
	}
	
	.clear-btn::after {
		border: none;
	}
</style> 